<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Log;

class Menu extends Model
{
    //
    protected $table = 't_menu';

    protected $primaryKey = "menu_id";

    public $child = array();

    public static function getSysMenus($parentId = 0){
        $menus = Menu::where("disabled","=",0)->where("parent_id","=",$parentId);
        $menus = $menus->get(); 
        foreach($menus as $menu){
            $childCount = Menu::getChildMenuCount($menu->menu_id);
            if($childCount > 0){
                $menu->child = Menu::getSysMenus($menu->menu_id);
            }
        }
        return $menus;
    }


    private static function getChildMenuCount($parentId = 0){
        $count = Menu::where("disabled","=",0)->where("parent_id","=",$parentId);
        $count = $count->count();
        return $count;
    }
     
}
